#include<bits/stdc++.h>
using namespace std;
int n,a[1005],t[1005],maxi=-1,ans;
int cou(){
    int s=0,k=0;
    for(int i=0;i<=maxi;i++){
        if(t[i]>=2){s++;k+=(t[i]-1)*i;}
    }
    ans=k;
    if(s==0) return 0;
    if(s==1) {ans=k;return 0;}
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>> T;
    while(T--){
        cin>>n;
        for(int i=0;i<n;i++){
            cin>>a[i];
            t[a[i]]++;
            maxi=max(maxi,a[i]);
        }
        //if(cou()==0){cout<<ans<<endl;continue;}
        cou();
        for(int i=0;i<=maxi;i++)t[i]=0;
        cout<<ans<<endl;
    }
    return 0;
}

